package ISOFT2.Pr03.Presentacion;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import ISOFT2.Pr03.Dominio.Cliente;

public class VerAsistencia extends JFrame {

	private JFrame frame;
	//VerListaAsignaturas window = new VerListaAsignaturas();
	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					VerListaAsignaturas window = new VerListaAsignaturas();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}*/

	public VerAsistencia() {
		
		initialize();
		frame.setVisible(true);
	}

	
	private void initialize() {
		Cliente c=new Cliente();
		final LinkedList<String[]>listaAsistencia=c.consultarAsistencia(0/*,0*/);
		
		frame = new JFrame();
		frame.setBounds(100, 100, 486, 347);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = new JPanel();
		frame.getContentPane().add(panel, BorderLayout.CENTER);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 23, 29, 0};
		gbl_panel.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		panel.setLayout(gbl_panel);
		
		JLabel lblAsignaturas = new JLabel("Asignaturas:");
		GridBagConstraints gbc_lblAsignaturas = new GridBagConstraints();
		gbc_lblAsignaturas.anchor = GridBagConstraints.EAST;
		gbc_lblAsignaturas.gridwidth = 4;
		gbc_lblAsignaturas.insets = new Insets(0, 0, 5, 5);
		gbc_lblAsignaturas.gridx = 2;
		gbc_lblAsignaturas.gridy = 2;
		panel.add(lblAsignaturas, gbc_lblAsignaturas);
		
		final JComboBox comboBox = new JComboBox();
		GridBagConstraints gbc_comboBox = new GridBagConstraints();
		gbc_comboBox.gridwidth = 5;
		gbc_comboBox.insets = new Insets(0, 0, 5, 5);
		gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_comboBox.gridx = 6;
		gbc_comboBox.gridy = 2;
		panel.add(comboBox, gbc_comboBox);
		for(int i=0; i<listaAsistencia.size(); i++){
			comboBox.addItem(listaAsistencia.get(i)[0]);
		}
		
		GridBagConstraints gbc_btnMostrar = new GridBagConstraints();
		gbc_btnMostrar.gridwidth = 2;
		gbc_btnMostrar.insets = new Insets(0, 0, 5, 5);
		gbc_btnMostrar.gridx = 12;
		gbc_btnMostrar.gridy = 2;
		
		JLabel lblNombreDeLa = new JLabel("Nombre de la Asignatura:");
		GridBagConstraints gbc_lblNombreDeLa = new GridBagConstraints();
		gbc_lblNombreDeLa.anchor = GridBagConstraints.EAST;
		gbc_lblNombreDeLa.gridwidth = 4;
		gbc_lblNombreDeLa.insets = new Insets(0, 0, 5, 5);
		gbc_lblNombreDeLa.gridx = 1;
		gbc_lblNombreDeLa.gridy = 5;
		panel.add(lblNombreDeLa, gbc_lblNombreDeLa);
		
		final JLabel mostrarAsignatura = new JLabel("");
		GridBagConstraints gbc_mostrarAsignatura = new GridBagConstraints();
		gbc_mostrarAsignatura.anchor = GridBagConstraints.WEST;
		gbc_mostrarAsignatura.gridwidth = 8;
		gbc_mostrarAsignatura.insets = new Insets(0, 0, 5, 5);
		gbc_mostrarAsignatura.gridx = 6;
		gbc_mostrarAsignatura.gridy = 5;
		panel.add(mostrarAsignatura, gbc_mostrarAsignatura);
		
		JLabel lblFaltas = new JLabel("Faltas:");
		GridBagConstraints gbc_lblFaltas = new GridBagConstraints();
		gbc_lblFaltas.anchor = GridBagConstraints.EAST;
		gbc_lblFaltas.gridwidth = 4;
		gbc_lblFaltas.insets = new Insets(0, 0, 5, 5);
		gbc_lblFaltas.gridx = 1;
		gbc_lblFaltas.gridy = 6;
		panel.add(lblFaltas, gbc_lblFaltas);
		
		final JLabel mostrarFaltas = new JLabel("");
		GridBagConstraints gbc_mostrarFaltas = new GridBagConstraints();
		gbc_mostrarFaltas.anchor = GridBagConstraints.WEST;
		gbc_mostrarFaltas.gridwidth = 8;
		gbc_mostrarFaltas.insets = new Insets(0, 0, 5, 5);
		gbc_mostrarFaltas.gridx = 6;
		gbc_mostrarFaltas.gridy = 6;
		panel.add(mostrarFaltas, gbc_mostrarFaltas);
		
		JButton btnMostrar = new JButton("Mostrar");
		panel.add(btnMostrar, gbc_btnMostrar);
		
		JLabel lblAñoAcademico = new JLabel("A\u00F1o Academico:");
		GridBagConstraints gbc_lblAñoAcademico = new GridBagConstraints();
		gbc_lblAñoAcademico.anchor = GridBagConstraints.EAST;
		gbc_lblAñoAcademico.gridwidth = 4;
		gbc_lblAñoAcademico.insets = new Insets(0, 0, 5, 5);
		gbc_lblAñoAcademico.gridx = 1;
		gbc_lblAñoAcademico.gridy = 7;
		panel.add(lblAñoAcademico, gbc_lblAñoAcademico);
		
		final JLabel mostrarAñoAcademico = new JLabel("");
		GridBagConstraints gbc_mostrarAñoAcademico = new GridBagConstraints();
		gbc_mostrarAñoAcademico.anchor = GridBagConstraints.WEST;
		gbc_mostrarAñoAcademico.gridwidth = 8;
		gbc_mostrarAñoAcademico.insets = new Insets(0, 0, 5, 5);
		gbc_mostrarAñoAcademico.gridx = 6;
		gbc_mostrarAñoAcademico.gridy = 7;
		panel.add(mostrarAñoAcademico, gbc_mostrarAñoAcademico);
		btnMostrar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nombre=comboBox.getSelectedItem().toString();
				for(int i=0; i<listaAsistencia.size(); i++){
					if(listaAsistencia.get(i)[0].equals(nombre)){
						mostrarAsignatura.setText(listaAsistencia.get(i)[0]);
						mostrarFaltas.setText(listaAsistencia.get(i)[1]);
						mostrarAñoAcademico.setText(listaAsistencia.get(i)[2]);
						i=listaAsistencia.size();
					}
				}
				
			}
		});
	}

}
